package com.lrl.security.validate.core.Sms;

import com.lrl.security.properties.SecurityProperties;
import com.lrl.security.validate.core.ValidateCode;
import com.lrl.security.validate.core.ValidateCodeGenerator;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
/**
 * @author LRL
 */
@Component("smsValidateCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    public ValidateCode createCode(ServletWebRequest request) {
        String code = RandomStringUtils.randomNumeric(securityProperties.getValidateCodeProperties().getSms().getLength());
        return new ValidateCode(code, securityProperties.getValidateCodeProperties().getSms().getExpireIn());
    }

    public SecurityProperties getSecurityProperties() {
        return securityProperties;
    }

    public void setSecurityProperties(SecurityProperties securityProperties) {
        this.securityProperties = securityProperties;
    }


}
